<template>
	<view class="listcontent">
		<navbar  :title="titlename" left-icon="left"  rightText="分享"
			@clickLeft="clicklefttext" @clickRight="clickrighttext">
			
			<view class="na-all" @click="clickrighttext">
				<view class="lleft">
					<image class="lleft" src="/static/tabBar/share.png" mode=""></image>
				</view>
			
			</view>
			
			</navbar>
		<view class="">
			<view class="" v-for="(item,index) in getdata" :key="item.id">
				<view class="listcontenttime">
					时间:{{item.time.split('T')[0]}}
				</view>
				<view class="formatted-text" v-html="formattedText">
					
				</view>

			</view>
		</view>
		<view v-if="isShow" class="reserva-detal" @touchmove.stop.prevent="">
			<!-- 阴影框 -->
			<view class="pop-mask" @tap="hidePop()">
			</view>
			<view class="pop-box" :animation="animationData">
				<view class="pop-btitle">
					<view class="pop-item">
						<view class="" v-for="(item,index) in list" :key="item.id" @click="gosharelist(item.id)">
							<image style="width: 100rpx;height: 100rpx;padding:30rpx 50rpx;" :src="item.img" mode=""></image>
							<view class="pop-item-title">
								{{item.title}}
							</view>
						</view>
						
					</view>
				</view>
		
				<view class="pop-sub" @tap="gocancel">
					取消
				</view>
			</view>
		</view>
		<tarbar></tarbar>
	</view>
</template>

<script>
	import $http from '@/common/api/request.js'
	import tarbar from '@/common/tabbar.vue'
	import navbar from "@/components/uni/uni-nav-bar/uni-nav-bar.vue"
	export default {
		data() {
			return {
				getindexid: 0,
				getdata: [],
				titlename: "",
				content: [],
				isShow: false,
				animationData: {}, //动画过渡
				list:[{id:0,title:"微信好友",img:"../../static/tabBar/weixin.jpg"},
					{id:1,title:"微信朋友圈",img:"../../static/tabBar/friend.jpg"},
					{id:2,title:"微信收藏",img:"../../static/tabBar/linka.jpg"},
					{id:3,title:"新浪微博",img:"../../static/tabBar/weibo.jpg"},
					{id:4,title:"QQ",img:"../../static/tabBar/qq.jpg"},
					{id:5,title:"商品二维码",img:"../../static/tabBar/shop.jpg"},
				]
			};
		},
		components: {
			tarbar,
			navbar
		},
		 computed: {
		    // 格式化文本，保留换行并空两格
		    formattedText() {
		      // 将换行符替换为带有两个空格的换行标签
		      const formatted = this.content.replace(/\n/g, '<br>&nbsp;&nbsp;');
		      // 返回处理后的文本
		      return `<span style="text-indent: -2em;">${formatted}</span>`;
		    },
		  },
		methods: {
			getcontent() {
				$http.request({
					url: "/listdata_r_c",
					method: "POST",
					data: {
						keyid: this.getindexid
					}
				}).then((res) => {
					uni.showToast({
						title: "获取数据中...",
						icon: "none",
						mask: true,
						duration: 500,
						success: () => {
							this.getdata = res;
							
							if (this.getdata.length > 0) {
								this.titlename = this.getdata[0].title,
								this.content = this.getdata[0].content;
							} else {

							}

						}
					})
				}).catch(() => {
					uni.showToast({
						title: "获取listdata_r数据失败",
						icon: "error",
						mask: true,
						duration: 2000
					})
				})
			},
			clicklefttext() {
				uni.navigateTo({
					url:"/pages/list/list"
				})
			},
			clickrighttext() {
				this.isShow = true;
				
			},
			gocancel(){
				this.isShow=false
			},
			hidePop() {
				var animation = uni.createAnimation({
					duration: 200,
				})
				animation.translateY(0).step()
				this.animationData = animation.export()
				setTimeout(() => {
					animation.translateY(600).step()
					this.isShow = false;
				}, 200)
			
			},
			gosharelist(index){
				if(index === 0){
					this.shareall("weixin","WXSceneSession")
				}else if(index === 1){
					this.shareall("weixin","WXSceneTimeline")
				}else if(index === 2){
					this.shareall("weixin","WXSceneFavorite")
				}else if(index === 3){
					this.shareall("sinaweibo","")
				}else if(index === 4){
					this.shareall("qq","")
				}else if(index === 5){
					this.shareall("weixin","WXSceneSession")
				}
				
			},
			shareall(provider,scene){
				uni.share({
					provider:provider,//微信
					type: 0,
					scene: scene,//WXSceneSession
					title: this.titlename,
					summary: `我正在看${this.titlename}，赶紧跟我一起来体验！`,
					href: `https://static-mp-226e15e0-3338-4b4a-a504-1a5766808d99.next.bspapp.com/#/pages/listcontent/listcontent?indexid=${this.getindexid}`,
					imageUrl: "https://zyc618.mynatapp.cc/images/index/%E6%95%A3%E5%85%B51.jpg",
					success: function(res) {
						uni.showTabBar({
							title: "分享成功"
						})
					},
					fail: function(err) {
						console.log("fail:" + JSON.stringify(err));
					}
				})
			}
		},
		onLoad(e) {
			this.getindexid = e.indexid;

		},
		onReady() {
			this.getcontent()
		}
	}
</script>

<style lang="scss">
	.reserva-detal {
		position: fixed;
		left: 0;
		top: 0;
		width: 100%;
		height: 100%;
		z-index: 999;
	
		.pop-mask {
			position: absolute;
			left: 0;
			top: 0;
			width: 100%;
			height: 100%;
			background-color: rgba(0, 0, 0, .6);
		}
	
		.pop-box {
			position: absolute;
			left: 0;
			bottom: 0;
			width: 100%;
			background-color: #ffffff;
			border-radius: 30rpx;
	
			.pop-btitle {
				height: 450rpx;
				.pop-item{
					display: flex;
					flex-wrap: wrap;
					justify-content: center;
					align-items: center;
					.pop-item-title{
						display: flex;
						justify-content: center;
						align-items: center;
					}
				}
			}
	
	
			.pop-sub {
				z-index: 9999;
				line-height: 80rpx;
				text-align: center;
				margin-bottom: 120rpx;
			}
		}
	}
	.listcontent {
		padding-bottom: 120rpx;

		.listcontentc {
			text-indent: 32.4px;
		}

		.listcontentname {
			display: flex;
			justify-content: end;
		}

		.listcontenttime {
			display: flex;
			justify-content: center;
		}
	}
	.na-all {
		width: 100%;
		display: flex;
		justify-content: end;
		align-items: center;
	
		.lleft {
			width: 40rpx;
			height: 40rpx;
		}
	
		.rright {
			width: 40rpx;
			height: 40rpx;
		}
	}
	.content{
		 text-indent: 2em; /* 设置开头空两格 */
	}
	.title{
		font-size: 38rpx;
		line-height: 38rpx;
		font-weight: 500;
		padding: 10rpx 20rpx;
		
	}
	.formatted-text {
	  white-space: pre-line; /* 保留换行 */
	}
</style>